#include "qbuttonhost.h"


#include "qcommonstruct.h"
#include "qabstractproperty.h"
#include "qpropertyfactory.h"

#include <QAbstractButton>
#include <QVariant>

using namespace SHAREDLIB;

QButtonHost::QButtonHost(QObject *object):
    QWidgetHost(object)
{
    QAbstractProperty *pro;

    pro=QPropertyFactory::createProperty("String");
    if(pro!=NULL)
    {
        pro->setAttribute("name","text");
        pro->setAttribute("property_name",tr("Text"));
        pro->setAttribute("group","Attributes");
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Bool");
    if(pro!=NULL)
    {
        pro->setAttribute("name","checkable");
        pro->setAttribute("property_name",tr("Checkable"));
        pro->setAttribute("group","Attributes");
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Bool");
    if(pro!=NULL)
    {
        pro->setAttribute("name","checked");
        pro->setAttribute("property_name",tr("Checked"));
        pro->setAttribute("group","Attributes");
        addProperty(pro);
    }


    pro=QPropertyFactory::createProperty("Script");
    if(pro!=NULL)
    {
        pro->setAttribute("name","clicked");
        pro->setAttribute("property_name",tr("Clicked"));
        pro->setAttribute("group","Events");
        m_object->setProperty("clicked","");
        addProperty(pro);
    }

    appendMemery("text");
    appendMemery("checkable");
    appendMemery("checked");

    QAbstractButton* button=(QAbstractButton*)m_object;
    connect(button,SIGNAL(clicked()),this,SLOT(clicked()));
}

void QButtonHost::setText(const QString &text)
{
    setPropertyValue("text",text);
}

QString QButtonHost::text()
{
    return getPropertyValue("text").toString();
}

void QButtonHost::setCheckable(bool checkable)
{
    setPropertyValue("checkable",checkable);
}

bool QButtonHost::checkable()
{
    return getPropertyValue("checkable").toBool();
}

void QButtonHost::setChecked(bool checked)
{
    setPropertyValue("checked",checked);
}

bool QButtonHost::checked()
{
    return getPropertyValue("checked").toBool();
}

void QButtonHost::clicked()
{
    QString code=getPropertyValue("clicked").toString();
    if(code!="")
    {
        QMap<QString,QString> param;
        emit_exec(code,param);
    }
}
